Function.prototype.myCall =  function (context) {
    if (typeof this !== 'function') {
        throw new Error('not a function err ！')
    }
    const args = [...arguments].slice(1)
    let result = null
    context = context || window
    context.fn = this
    result = context.fn(...args)
    delete context.fn
    return result
}

Function.prototype.myApply =  function (context) {
    if (typeof this !== 'function') {
        throw new Error('not a function err !')
    }
    
    let result = null
    context = context || window
    const fnSymbol = Symbol()
    context[fnSymbol] = this
    if (arguments[1]) {
        console.log(`apply 有形参`)
        result = context[fnSymbol](...arguments[1])
    } else {
        console.log(`apply 无形参`)
        result = context[fnSymbol]()
    }
    delete context[fnSymbol]
    return result
}

Function.prototype.myBind =  function (context) {
    if (typeof this != 'function') {
        throw new Error('not function err !')
    }
    const args = [...arguments].slice(1)
    const fn = this
    return function Fn () {
        return fn.apply(
            this instanceof Fn ? this : context,
            args.concat(...arguments)
        )
    }
}

